package com.xsherl.leetcode.solution;

public class ClimbingStairs {

    /**
     * 等价于求斐波拉契数列第n数
     */
    public int climbStairs(int n) {
        if (n == 1){
            return 1;
        }
        if (n == 2){
            return 2;
        }
        int f1 = 1, f2 = 2;
        for (int i = 3; i <= n; ++i){
            int t = f2;
            f2 += f1;
            f1 = t;
        }
        return f2;
    }

    public static void main(String[] args) {
        int n = 4;
        int i = new ClimbingStairs().climbStairs(n);
        System.out.println(i);
    }
}
